#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
    int n,k;
    scanf("%d%d", &n, &k);
    int a[n];
    long long all=0;
    for (int i=0; i<n; i++) {
        scanf("%d", &a[i]);
        all+=a[i];
    }
    int ave=all/n;
    sort(a,a+n);
    int l=0, r=ave;
    int mid,tmp1,tmp2;
//    printf("r=%d\n", r);
    while (l<=r) {
        mid = (l+r)/2;
        int i=0;
        long long tmp=0;
        while (a[i]<mid) {
            tmp+=mid-a[i];
            i++;
        }
        if (tmp>k)
        	r=mid-1;
        else {
        	tmp1=mid;
        	l=mid+1;
		}
    }
    cout<<"tmp1: "<<tmp1<<endl;
    l=(all+n-1)/n; //for the special examples, such as: 1 1 1 2
    r=a[n-1];
    while (l<=r) {
        mid = (l+r)/2;
        int i=n-1;
        long long tmp=0;
        while (a[i]>mid) {
            tmp+=a[i]-mid;
            i--;
        }
        if (tmp>k) l=mid+1;
        else {
        	tmp2=mid;
        	r=mid-1;
		}
    }
    cout<<"tmp2: "<<tmp2<<endl;
    printf("%d", tmp2-tmp1);
    return 0;
}
